/**
 * Copyright (c) 2010 Basil Shikin, BugStat Project
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.bugstat.gui;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.bugstat.common.TimeInterval;
import org.bugstat.common.TimeStep;
import org.bugstat.common.reports.Report;
import org.bugstat.exporters.BugInfoReader;
import org.bugstat.exporters.ConnectionManager;
import org.bugstat.exporters.ConnectionManager.DatabaseType;
import org.bugstat.exporters.StorageManager;
import org.bugstat.exporters.systems.bugzilla.BugzillaExporter;
import org.bugstat.generators.GeneratorManager;
import org.bugstat.generators.ReportGenerator;
import org.bugstat.generators.reports.generators.OpenBugsPerPerson;
import org.bugstat.generators.reports.generators.OpenBugs;
import org.bugstat.renderers.RendererManager;
import org.bugstat.renderers.ReportInformation;
import org.bugstat.renderers.ReportRenderer;
import org.bugstat.renderers.ReportInformation.ImportantDate;
import org.bugstat.renderers.csv.CSVReportRenderer;

/**
 * THIS FILE SHOULD NOT BE EVER CHECKED IN 
 *
 * @author Basil Shikin
 *
 */
public class ProcessEverything
{
    public static void main(String[] args) throws Exception
    {
        File storage = new File("/Users/ceasar/Temp/111/bugs");
        
        final long b = System.currentTimeMillis();
        Properties databaseProperties = new Properties();
        databaseProperties.setProperty( ConnectionManager.KEY_DATABASE, "da_bugzilla" );
        databaseProperties.setProperty( ConnectionManager.KEY_HOST, "localhost" );
        databaseProperties.setProperty( ConnectionManager.KEY_PORT, "3306" );
        databaseProperties.setProperty( ConnectionManager.KEY_USERNAME, "bugs" );
        databaseProperties.setProperty( ConnectionManager.KEY_PASSWORD, "bugs" );
                        
        
        final ConnectionManager connectionManager = new ConnectionManager( DatabaseType.MY_SQL, databaseProperties);
        connectionManager.ensureCanConnect();
        
        
        final StorageManager storageManager = new StorageManager( storage );
        final BugzillaExporter exporter = new BugzillaExporter();
        exporter.setManagers( connectionManager, storageManager);

        final TimeInterval ti = new TimeInterval( exporter.retrieveFirstBugDate(), TimeStep.WEEK );
        final ReportInformation reportInformation = new ReportInformation("Test Reports", ti, Collections.<ImportantDate>emptyList() );
        
        exporter.exportBugs( ti, null );
        
        final BugInfoReader reader = new BugInfoReader( storage );
        reader.initializeReader();
        
        final GeneratorManager genMgr = new GeneratorManager( reader );
        final List<ReportGenerator> gens = new ArrayList<ReportGenerator>();
        gens.add( new OpenBugs() );
        gens.add( new OpenBugsPerPerson() );
        
        final List<Report> reports = genMgr.generateReports( ti, gens, null);
        
        final RendererManager rMgr = new RendererManager();
        rMgr.renderReports(reports, reportInformation, storage, Arrays.<ReportRenderer>asList( new CSVReportRenderer() ), null );
        
        final long a = System.currentTimeMillis();
        System.out.println( "All done in " + (a-b) + "ms");
    }
}
